package com.atguigu.java.ai.langchain4j.mapper.impl;

import com.atguigu.java.ai.langchain4j.entity.Appointment;
import com.atguigu.java.ai.langchain4j.mapper.AppointmentMapper;
import com.atguigu.java.ai.langchain4j.service.AppointmentService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service
public class AppointmentServiceImpl extends ServiceImpl<AppointmentMapper, Appointment>
        implements AppointmentService {
    /**
     * 查询订单是否存在
     *
     * 此方法用于检查数据库中是否存在与给定条件匹配的预约订单
     * 它通过用户名、身份证号、部门、日期和时间来精确查询
     *
     * @param appointment 包含查询条件的预约对象
     * @return 如果存在匹配的订单，则返回该订单对象；否则返回null
     */
    @Override
    public Appointment getOne(Appointment appointment) {
        // 创建Lambda查询包装器，用于构建查询条件
        LambdaQueryWrapper<Appointment> queryWrapper = new LambdaQueryWrapper<>();
        // 添加查询条件：用户名等于给定的用户名
        queryWrapper.eq(Appointment::getUsername, appointment.getUsername());
        // 添加查询条件：身份证号等于给定的身份证号
        queryWrapper.eq(Appointment::getIdCard, appointment.getIdCard());
        // 添加查询条件：部门等于给定的部门
        queryWrapper.eq(Appointment::getDepartment, appointment.getDepartment());
        // 添加查询条件：日期等于给定的日期
        queryWrapper.eq(Appointment::getDate, appointment.getDate());
        // 添加查询条件：时间等于给定的时间
        queryWrapper.eq(Appointment::getTime, appointment.getTime());
        // 使用baseMapper执行查询，并返回查询结果
        Appointment appointmentDB = baseMapper.selectOne(queryWrapper);
        return appointmentDB;
    }

}